<template>
  <div class="home-recommond">
    <div id="tit"><h3>歌手</h3></div>
    <div class="wrapper" ref="wrapper">
      <ul class="content" ref="content">
        <li
          v-for="(item, index) in listData"
          :key="index"
          @click="selectItem(item)"
        >
          <div class="cover">
            <van-image :src="item.singer_pic" radius="1rem"></van-image>
          </div>
          <span>{{ item.singer_name }}</span>
        </li>
      </ul>
    </div>
  </div>
</template>
    <script>
// import BScroll from "better-scroll"; //引入betterscroll
import { betterScrollHorizontal } from "../../common/betterScroll.js";

export default {
  data() {
    return {
      listData: [],
    };
  },
  created() {
    this.getSongListData();
  },
  methods: {
    //获取数据
    getSongListData() {
      this.$request("get", "/singer/list").then((res) => {
        console.log(res);
        if (res.result == 100) {
          this.listData = res.data.list;
        }
        betterScrollHorizontal(
          this,
          this.$refs.wrapper,
          this.$refs.content,
          this.listData.length,
          10
        );
      });
    },
    selectItem(item) {
      const singerid = item.singer_mid; //获取到歌手id
      // console.log(id);
      // this.$router.push({
      //   name: "songlist",
      //   params: {singer
      //     id: id,
      //   },singer
      // });
      // this.$store.commit("saveSinger",item)
      this.$store.dispatch("saveSinger", item);
      this.$router.push({ path: `/singer/${singerid}` });
    },
  },
};
</script>
    <style scoped>
/* 
  */
.wrapper {
  width: 100%; /*容器宽度（屏幕宽度）*/
  overflow: hidden;
}

ul.content > li {
  display: inline-block;
  width: 10rem;
  vertical-align: top; /*垂直方向的位置 */
}
ul.content > li * {
  margin: 0 0.1rem;
}
ul.content > li > span {
  font-size: 0.8rem;
  color: #459efc;
}
.cover {
  position: relative;
}
.cover > span {
  position: absolute;
  right: 0;
  bottom: 0.4rem;
  background-color: rgb(183, 251, 205);
  color: white;
  font-size: 14px;
  border-radius: 1rem;
  width: 5rem;
  display: inline-block;
}
</style>